/*
* @Author: chenggh
* @Date: 2025-06-18
* @Link to Problem : https://oj.haizeix.com/problem/183
*/
#include <iostream>
using namespace std;

int f(int x){
	if(x <= 0) return 0;
	if(x == 1) return 1;
	if(x % 2 == 0) return f(x / 2) * 3 - 1;
	return f((x + 1) / 2) * 3 - 1;
}

int main(){
	int x; cin >> x;
	cout << f(x) << endl;
	return 0;
}